package test;

public class Demo4 {
    public int getMaxLen(int[] nums) {
        int maxCount = 0,minCount = 0,max = 0;
        for(int n : nums){
            if(n == 0){
                maxCount = 0;
                minCount = 0;
            }else if(n > 0){
                maxCount++;
                if(minCount > 0)
                    minCount++;
            }else{
                int temp = maxCount;
                maxCount = minCount;
                minCount = temp;
                minCount++;
                if(maxCount > 0)
                    maxCount++;
            }
            max = Math.max(minCount,maxCount);
        }
        return max;
    }

    public static void main(String[] args) {
        Demo4 d4 = new Demo4();
        int[] nums = {-1,-2,-3,0,1};
        System.out.println(d4.getMaxLen(nums));
    }
}
